<style lang="less">
// import在默认情况下会把后面的路径当做绝对路径去处理  因此这里引入应当加~ webpack就会按照相对路径去处理，就可以加别名了
@import '~$common/funs.less';
.cps-bottom-tip {
  background-color: #ffffff;
  // text-align: center;
  border-radius: 30px 30px 0 0;
  overflow: hidden;
  transition: transform 0.3s ease-out, opacity 0.15s ease-out;
  .header {
    display: flex;
    .-border-half(bottom);
    color: @font-primary;
    font-size: 36px;
    line-height: 120px;
    .title {
      flex: 1;
      padding-left: 30px;
      text-align: center;
      font-weight: bold;
    }
    .close {
      padding: 0 30px;
      color: @font-hint;
    }
  }
  .detail {
    word-break: break-all;
    // white-space: pre-wrap;
    padding: 40px 30px;
    max-height: 780px;
    overflow: auto;
    font-size: 26px;
    line-height: 40px;
    overscroll-behavior: contain;
    box-sizing: border-box;
    a {
      color: @font-link;
    }

    color: #333;
    line-height: 1.5;
    // h1 {
    //     border-bottom: none;
    //     .-border-half;
    // }
    li {
      padding-bottom: 24px;
    }
    ol {
      margin: 0 0 0 30px;
      padding: 0;
      list-style-type: decimal;
    }
    ul {
      margin: 0 0 0 30px;
      padding: 0;
      list-style-type: disc;
    }
    background-color: #ffffff;
  }
}
</style>

<template>
  <div>
    <simple-mask v-bind="$attrs" type="bottom" v-if="this.moreLevels" v-show="showCurrentMask">
      <div class="cps-bottom-tip iphonex-fixed-bottom">
        <div class="header">
          <div class="title">{{ title }}</div>
          <div class="close" @click="closePop">
            <icon-close></icon-close>
          </div>
        </div>
        <slot name="top"></slot>
        <div class="detail" :style="contextStyle" :class="contextClass" ref="detail" v-html="html" v-if="leonisId"></div>
        <div class="detail" :style="contextStyle" :class="contextClass" ref="detail" v-if="!leonisId">
          <slot></slot>
        </div>
      </div>
    </simple-mask>
    <simple-mask-two-level v-bind="$attrs" type="bottom" v-else v-show="showCurrentMask">
      <div class="cps-bottom-tip iphonex-fixed-bottom">
        <div class="header">
          <div class="title">{{ title }}</div>
          <div class="close" @click="closePop">
            <icon-close></icon-close>
          </div>
        </div>
        <slot name="top"></slot>
        <div class="detail" :style="contextStyle" :class="contextClass" ref="detail" v-html="html" v-if="leonisId"></div>
        <div class="detail" :style="contextStyle" :class="contextClass" ref="detail" v-if="!leonisId">
          <slot></slot>
        </div>
      </div>
    </simple-mask-two-level>
    <!-- <component :is="bottomTip" v-bind="$attrs" type="bottom" v-show="showCurrentMask">
    </component> -->
  </div>

</template>

<script>
export default {
  name: 'cps-bottom-tip',
  components: {
    iconClose: require('../../svg/close.vue').default,
    simpleMaskTwoLevel: require('../mask/index_two_level').default
  },
  props: {
    // 标题
    title: {
      type: String,
      default: ''
    },
    moreLevels: {
      type: Boolean,
      default: false
    },
    leonisId: {
      type: String,
      default: ''
    },
    // ** 中间组件始终不写showMask，和popName 这只是给最终孙子弹层用的
    // showMask: {
    //     type: Boolean,
    //     default: true
    // },
    contextClass: {
      type: String,
      default: ''
    },
    contextHeight: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      html: '',
      showCurrentMask: true
    }
  },
  created() {
    // console.log(this.$parent)
    // console.log(this.maskStatus)
  },
  inject: ['closePopMask'],
  computed: {
    contextStyle() {
      let style = {}
      if (this.showMask) {
        style.maxHeight = (window.innerHeight * 0.75 || 780) + 'px'
      }
      if (this.contextHeight) {
        style.height = this.contextHeight + 'px'
      }
      return style
    },
    bottomTip() {
      return this.simpleMaskTwoLevel
    }
  },
  watch: {
    //  ** 子组件这里监听showMask
    '$attrs.showMask'(nv, ov) {
      if (nv != ov) {
        this.$nextTick(() => {
          try {
            this.$refs.detail.scrollTop = 0
          } catch (e) {}
        })
      }
    }
  },
  mounted() {
    if (this.leonisId) {
      try {
        this.$model.leonis.dispatch(this.leonisId, res => {
          this.html = res
        })
      } catch (e) {}
    }
  },
  methods: {
    closePop() {
      this.closePopMask()
      this.showCurrentMask = false
    }
  }
}
</script>